//
//  YXYProgressHUD.m
//  GanJie
//
//  Created by 杨肖宇 on 2017/10/26.
//  Copyright © 2017年 yxy. All rights reserved.
//

#import "YXYProgressHUD.h"

@implementation YXYProgressHUD

+ (instancetype)showHUDAddedTo:(UIView *)view text:(NSString *)text animated:(BOOL)animated{
    if (!view) {
        return nil;
    }
    return [YXYProgressHUD showHUDAddedTo:view text:text delay:2];
}

+ (instancetype)showHUDAddedTo:(UIView *)view text:(NSString *)text delay:(NSUInteger)delay{
    MBProgressHUD * hh = [MBProgressHUD HUDForView:view];
    [hh hideAnimated:YES];
    
    MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    [hud hideAnimated:YES afterDelay:delay];
    return (YXYProgressHUD *)hud;
}

+ (void)showText:(NSString *)text autoHiden:(BOOL)hide{
    dispatch_async(dispatch_get_main_queue(), ^{
        MBProgressHUD * hud1 = [MBProgressHUD HUDForView:KEY_WINDOW];
//        MBProgressHUD * hud1 = [MBProgressHUD HUDForView:GETCURRENTCONTROLLER.view];
        [hud1 hideAnimated:YES];
        
        if (!text.length) return;
        
        MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:KEY_WINDOW animated:YES];
//        MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:GETCURRENTCONTROLLER.view animated:YES];
        hud.mode = MBProgressHUDModeText;
        hud.label.text = text;
        hud.label.numberOfLines = 0;
        if (hide) {
            [hud hideAnimated:YES afterDelay:2];
        }
    });
}
    
+ (YXYProgressHUD *)GetCurrentHUD{
    return (YXYProgressHUD *)[MBProgressHUD HUDForView:KEY_WINDOW];
//    return (YXYProgressHUD *)[MBProgressHUD HUDForView:GETCURRENTCONTROLLER.view];
}
    
@end
